/**
 * @author Tobias Boehm
 *
 * 03.06.2011
 */
package org.anddev.andengine.extension.tbsengine.message.server.ingame;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.anddev.andengine.extension.tbsengine.match.Round;
import org.anddev.andengine.extension.tbsengine.message.ICopyable;
import org.anddev.andengine.extension.tbsengine.message.server.AbsServerMatchMessage;

/**
 * This message should be send to all players of a match if a new round begins.
 * 
 * @author Tobias Boehm
 *
 */
public class ServerMatchRoundAnnouncementMessage extends AbsServerMatchMessage implements ICopyable<ServerMatchRoundAnnouncementMessage> {

	private boolean mRoundOpen = false;
	private int mRoundID = -1;
	
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.multiplayer.protocol.adt.message.IMessage#getFlag()
	 */
	@Override
	public short getFlag() {
		
		return FLAG_SERVER_MATCH_ROUND_ANNOUNCEMENT;
	}

	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.tbsengine.server.messages.shared.AbsServerMatchMessage#onReadTransmissonMatchData(java.io.DataInputStream)
	 */
	@Override
	protected void onReadTransmissonMatchData(final DataInputStream pDataInputStream)
			throws IOException {
				
		this.mRoundID = pDataInputStream.readInt();
		
		this.mRoundOpen = pDataInputStream.readBoolean();
	}

	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.tbsengine.server.messages.shared.AbsServerMatchMessage#onWriteTransmissonMatchData(java.io.DataOutputStream)
	 */
	@Override
	protected void onWriteTransmissonMatchData(final DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeInt(this.mRoundID);
		pDataOutputStream.writeBoolean(this.mRoundOpen);
	}
	
	public void setRound(final Round pRound){
		
		this.mRoundOpen = pRound.isRoundOpen();
		this.mRoundID = pRound.getRoundID();
	}

	@Override
	public ServerMatchRoundAnnouncementMessage copy() {
		
		final ServerMatchRoundAnnouncementMessage copy = new ServerMatchRoundAnnouncementMessage();
		
		copy.mMatchID = this.mMatchID;
		copy.mRoundID = this.mRoundID;
		copy.mRoundOpen = this.mRoundOpen;
		
		return copy;	
	}

	/**
	 * @return the mRoundOpen
	 */
	public boolean isRoundOpen() {
		return mRoundOpen;
	}

	/**
	 * @return the mRoundID
	 */
	public int getRoundID() {
		return mRoundID;
	}
}
